package com.xigua.a03_bean生命周期;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.util.ArrayList;
import java.util.List;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/4/117:46
 */
public class TestMethodTemplate {

    public static void main(String[] args) {
        MyBeanFactory beanFactory = new MyBeanFactory();
        beanFactory.addBeanPostProcessor(bean-> System.out.println("解析Autowired"));
        beanFactory.getBean();

    }

    static class MyBeanFactory{

        private List<BeanPostProcessor> processors =  new ArrayList<>();

        public Object getBean(){
            Object bean = new Object();
            System.out.println("构造"+bean);
            System.out.println("依赖注入"+bean);
            for (BeanPostProcessor processor : processors) {
                processor.inject(bean);
            }
            System.out.println("初始化"+bean);
            return bean;
        }

        public void addBeanPostProcessor(BeanPostProcessor processor){
            processors.add(processor);
        }
    }

     interface BeanPostProcessor{
        void inject(Object bean);
    }

}
